<template>
  <div>
    <div>
        <el-button @click="authentic(null,1)">批量认证</el-button>
    </div>
    <el-table
      :data="dataList"
      @selection-change="handleSelectionChange"
      style="width: 100%">
      <el-table-column
      type="selection"
      width="55">
    </el-table-column>
      <el-table-column
        prop="id"
        fixed
        width="100">
      </el-table-column>
      <el-table-column
        prop="activeName"
        label="活动名称"
        width="180">
      </el-table-column>
      <el-table-column
        prop="acriveAddress"
        width="180"
        label="活动地址">
      </el-table-column>
      <el-table-column
        prop="createTime"
        width="140"
        label="报名时间">
      </el-table-column>
      <el-table-column
        prop="deadTime"
        width="140"
        label="截止时间">
      </el-table-column>
      <el-table-column
        label="状态">
        <template slot-scope="scope">
            <el-tag :type="scope.row.isAuthentic===0?'primary':'success'">{{ scope.row.isAuthentic===0?'未认证':'已认证' }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        width="100"
        label="操作">
        <template slot-scope="scope">
            <div>
                <el-button @click="authentic(scope.row.id,2)" 
                    :disabled="scope.row.isAuthentic===0?false:true">认证</el-button>
            </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import request from '@/util/request';
export default {
    data(){
        return{
            authenticList:[]
        }
    },
    props:{
        dataList:{
            type:Array,
            default:()=>[],
        }
    },
    methods:{
        handleSelectionChange(item){
            console.log(item);
            this.authenticList = item
        },
        authentic(id,type){
            var arr = []
            if(type===1){
                // 批量认证
                arr = this.authenticList.map(item=>item.id)
            }else {
                // 单个认证
                arr.push(id)
            }
            console.log(arr);
            if(arr.length<=0){
                this.$notify.warning('抱歉，没有选择活动')
                return;
            }
            request.post('/admin/authentic/authentic',arr).then((res) => {
                this.$notify.success('操作成功')
                this.$emit('refresh')
            })
            .catch(err =>{
                if (err.response) {
                    this.$notify.error(err.message)
                } else {
                    this.$notify.error('网络错误')
                } 
            })
        }
    }
}
</script>

<style>

</style>